﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using LibRTC.Core;
using LibRTC.Interface;
using RTCCore;

namespace LibGUI.LogOn
{
    public partial class LogOnForm : Form, ILogOnUI
    {
        private IRTCCoreOperations rtcOperations;

        public LogOnForm()
        {
            InitializeComponent();
        }

        public void SetRTCOperations(IRTCCoreOperations rtcCoreOperations)
        {
            this.rtcOperations = rtcCoreOperations;            
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            // config the profile here

            if("192.168.150".Equals(comboBoxProfile.SelectedText))
            {
                // local server used for test
                RTCSystem.GetInstance().SetSipRealm("192.168.0.150");
                RTCSystem.GetInstance().SetSipServerIp("192.168.0.150");
                RTCSystem.GetInstance().SetSipServerName("192.168.0.150");
            }
            else if ("vcedu.3322.org".Equals(comboBoxProfile.SelectedText))
            {
                // server which is in edu
                RTCSystem.GetInstance().SetSipRealm("vcedu.3322.org");
                RTCSystem.GetInstance().SetSipServerIp("166.111.134.27");
                RTCSystem.GetInstance().SetSipServerName("vcedu.3322.org");                
            }
            else
            {
                // do nothing
            }

            rtcOperations.DoLogOn(userName.Text,passWord.Text, RTC_PRESENCE_STATUS.RTCXS_PRESENCE_ONLINE);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        public void LogOnSucc()
        {
            //clean the reference in case there is a memory leak
            this.rtcOperations = null;

            DialogResult = DialogResult.OK;

        }

        public void LogOnFail()
        {
            MessageBox.Show("UserName password Error", "Error");
        }

        public void LogOnError()
        {
            MessageBox.Show("UserName password Error", "Error");
        }
    }
}